Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var record_start = 0; 

var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",
width:40, 
renderer:function(value,metadata,record,rowIndex){ 
return record_start + 1 + rowIndex; 
} 
}),
{header:'客户ID',dataIndex:'custId',hidden:true},
{header:'客户名称',dataIndex:'custName',width:100},
{header:'所属行业',dataIndex:'industryType',width:100}, 
{header:'信用评级',dataIndex:'creditLevel',width:100},
{header:'信贷余额(元)',dataIndex:'debtSum',width:100},
{header:'风险暴露分类',dataIndex:'exposureType',width:100},
{header:'违约状态',dataIndex:'defaultStat',width:100},
{header:'经办人',dataIndex:'inputUserName',width:100},
{header:'经办机构',dataIndex:'inputOrgName',width:100},
]); 
var ds=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'customer/listCustomer.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ 
totalProperty:'total',  
root:'customer'},[
{name:'custId'}, 
{name:'custName'},  
{name:'industryType'},
{name:'creditLevel'},
{name:'debtSum'},
{name:'exposureType'},
{name:'defaultStat'},
{name:'inputUserName'},
{name:'inputOrgName'},
]) 
}); 
ds.load({params:{start:0,limit:20}}); 

var conditionStore = new Ext.data.SimpleStore({
	   fields : ['id', 'text'],
	   data : [['custId', '客户编号'], ['custName', '客户名称']]
});

var grid=new Ext.grid.GridPanel({ 
id:'myCustomers',
renderTo:"customer_list", 
stripeRows:true,//斑马线效果
title:"我的客户列表", 
height:500, 
cm:cm,
store: ds, 
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 20,   
                store: ds,
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据"  ,
                doLoad : function(start){ 
   record_start = start; 
var o = {}, pn = this.getParams(); 
          o[pn.start] = start; 
          o[pn.limit] = this.pageSize; 
this.store.load({params:o}); 
     }     
            }),
 tbar: [
 {text:'违约事件登记',handler: listDefault},   
 '->',
 {xtype:'combo',
 id:'condition',
 name: 'condition', 
 store: conditionStore,
 fieldLabel: '请选择查询条件',
 valueField : 'id',
 displayField : 'text',
 emptyText : '请选择查询条件',
 triggerAction : 'all',
 editable: false,
 mode:'local',
 width:110
 },'',
 {xtype:'textfield',id:'keyword',width:180},
 {text:'查询',handler:findCustomer},
 '-',
 {text:'清空',handler: callBack} ]   
});
ds.load({params:{start:0,limit:20}}); 



function findCustomer(){

var condition = Ext.getCmp('condition').getValue();
var keyword = Ext.getCmp('keyword').getValue();

if(condition == '' || condition == null){
Ext.Msg.alert('提示', '请选择查询条件！'); 
}
else{

ds.baseParams={condition:condition, keyword: keyword};
ds.proxy = new Ext.data.HttpProxy({
				url:'customer/findCustomer.do',
				method:'POST'
			}); 
ds.reader = new Ext.data.JsonReader({ 
					totalProperty:'total',  
					root:'resultData'},[
										{name:'custId', mapping: 'custId'}, 
										{name:'custName', mapping: 'custName'},  
										{name:'industryType', mapping: 'industryType'},
										{name:'defaultStat', mapping: 'defaultStat'},
										{name:'exposureType', mapping: 'exposureType'},
										{name:'creditLevel',mapping:'creditLevel'},
										{name:'balance',mapping:'balance'},
										{name:'inputUserName', mapping:'inputUserName'},
										{name:'inputOrgName', mapping:'inputOrgName'},
]);
				   
ds.load({params:{start:0,limit:20}});
record_start = 0;  	
}
}

function callBack(){

Ext.getCmp('condition').clearValue();
Ext.getCmp('keyword').setValue('');
ds.proxy = new Ext.data.HttpProxy({
				url:'customer/listCustomer.do',
				method:'POST'
			}); 
ds.reader = new Ext.data.JsonReader({ 
					totalProperty:'total',  
					root:'customer'},[
										{name:'custId', mapping: 'custId'}, 
										{name:'custName', mapping: 'custName'},  
										{name:'industryType', mapping: 'industryType'},
										{name:'defaultStat', mapping: 'defaultStat'},
										{name:'exposureType', mapping: 'exposureType'},
										{name:'creditLevel',mapping:'creditLevel'},
										{name:'balance',mapping:'balance'},
										{name:'inputUserName', mapping:'inputUserName'},
										{name:'inputOrgName', mapping:'inputOrgName'},
				]);   
ds.load({params:{start:0,limit:20}});
record_start = 0;

}


function listDefault(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要操作的项！"); 
}
else{
	var selectedCustId = grid.getSelectionModel().getSelections()[0].data.custId;
	window.location.href="obligation/showCustDE.do?custId="+selectedCustId;
}
}


function rowdblclickFn(grid, rowIndex, e){//双击事件  
             var row = grid.getStore().getAt(rowIndex); 
             var selectedCustId = row.get("custId");
             Ext.Ajax.request({
  url:'checkRequest.do',
  method:'GET',
  success:function(){
  window.location.href="obligation/showCustDE.do?custId="+selectedCustId;
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});  
}   
grid.addListener('rowdblclick',rowdblclickFn);
}); 